<?php

try
{
	$database = new PDO('mysql:host=localhost;dbname=club_basket', 'root', '');
}
catch (Exception $e)
{
        die('Erreur : ' . $e->getMessage());
}

$request_moy_pts = 'SELECT AVG(MOYENNE_FAUTES) AS AVG_PLR_FAULT,
       AVG(MOYENNE_PTS) AS AVG_PLR_PTS
FROM
(SELECT AVG(FAUTES) AS MOYENNE_FAUTES,
       AVG(POINTS) AS MOYENNE_PTS
FROM INDIVIDU INNER JOIN LICENCIE USING(ID_INDIVIDU)
     	      INNER JOIN JOUEUR USING(ID_LICENCIE)
	      INNER JOIN PARTICIPATION USING(ID_JOUEUR)
GROUP BY ID_JOUEUR)T1';

$request_moy_match = 'SELECT AVG(PARTICIPATIONS) AS AVG_PLR_PART
FROM
(SELECT ID_JOUEUR, COUNT(ID_PARTICIPATION) AS PARTICIPATIONS
FROM PARTICIPATION 
GROUP BY ID_JOUEUR)T1';

$data_moy_pts = $database->query($request_moy_pts);
$data_moy_match = $database->query($request_moy_match);


echo '</br><h2>Statistics database information</h2>';
echo '<p> For the records, here are some statistic information about our database :</br>';

if($moy_pts = $data_moy_pts->fetch()) {
echo ' - The average score per match of a player is <strong>' . $moy_pts['AVG_PLR_PTS'] . '</strong></br>';
echo ' - The average fault number per match of a player is <strong>' . $moy_pts['AVG_PLR_FAULT'] . '</strong></br>';

}
if($moy_match = $data_moy_match->fetch()) echo ' - The average number of played match per player is <strong>' . $moy_match['AVG_PLR_PART'] . '</strong></br>';

echo '</p>';

$data_moy_pts->closeCursor();
$data_moy_match->closeCursor();

?>